import 'dart:ui' as ui;
import 'package:flutter/material.dart';
import '../pages/openCV_provider.dart';

class InfraredPage extends StatefulWidget {
  const InfraredPage({Key? key}) : super(key: key);

  @override
  _InfraredPageState createState() => _InfraredPageState();
}

class _InfraredPageState extends State<InfraredPage>
  with SingleTickerProviderStateMixin {
  var openCVProvider = new OpenCVProvider();
  bool ready = false;
  late ui.Image _image;

  
  @override
  void initState() {
    super.initState();
    _loadImage();
  }

  Future<void> _loadImage() async {
      final ui.Image image = await openCVProvider.main();
      setState(() {
        _image = image;
        ready = true;
      });
  }

  @override
  Widget build(BuildContext context) {
    double screenWidth = MediaQuery.of(context).size.width;
    double amplificationCoefficient = openCVProvider.getAmplificationCoefficient(screenWidth);

    return Scaffold(
      appBar: AppBar(
        title: const Text('红外解析'),
      ),
      body: Center(
        child: ready ? RawImage(
          image: _image,
          width: screenWidth,
          height: screenWidth * amplificationCoefficient,
          fit: BoxFit.contain,
        ) : const CircularProgressIndicator(),
      ),
    );
  }
}
